Build-MacOSX
Introduction This page covers building Freeciv from source on Mac OS X. As an easier option, you may instead want to investigate using a package manager as described at Install-MacOSX. The contents are taken, in part, from here. This page assumes familiarity with development tools like make gcc and git. The good news is that Freeciv compiles on Mac OS X without any source code modification. This was written with: *Freeciv ** 2.1.3 ** 2.1.10 (installs via macports as freeciv-x11) ** 2.2.0-beta2 (GTK+2 client, compiles from source tarball without modifications using macports for prerequisites) * Mac OS X ** 10.4.11 ** 10.5.8 ** 10.8 (Mountain Lion) - You must install XQuartz; Mountain Lion no longer includes X11 - see HT201341 ** 10.13.5 (High Sierra) - see gettext workaround below (please add on if these instructions have worked) Possible Clients Freeciv supports several clients on Mac OS X: * GTK 3.22 as of FreeCiv version 2.6.0 (recommended for Sierra onwards - this version has feature parity with GTK 3 and drops lots of backward compatibility) * GTK+2 (recommended) ** GTK2 +x11 (ported from linux) ** GTK2 +quartz (under development) * GTK+1 (deprecated) * SDL * xaw (does not require supporting libraries -- ie. port or fink) (deprecated) the x11 / quartz choice is purely a Mac issue, and does not seem to be covered elsewhere. Before You Start There are several tools that are useful in this process, and will make our job *much* easier. These are: * Git revision control system. Similar to Subversion or cvs. * MacPorts package system for many open source packages * Homebrew Package system. Similar to MacPorts. * Fink Package system. Similar to MacPorts. Although the source code does not need modification, it takes a good bit of work to lay the foundation so that you can compile Freeciv on top of it. Thankfully heavy lifting can be done for you by a package manager like port or fink, mentioned above. Prepare Mac OS X Installing MacPorts *Head over to MacPorts, follow the installation instructions to install MacPorts. *The default install paths for macports is /opt/local/*. Because these aren't always included in the default paths, you may need to add them to the normal compiler search paths: % export CC="gcc -I/opt/local/include/ -L/opt/local/lib/" * You will notice this problem if libraries fail to link while compiling. * Note: At least with MacOSX 10.5.8, only macports is needed. To ease fulfilling the requirements, the package for freeciv-x11 (pointing to 2.1.10 as of current) can be installed and disabled before building freeciv 2.2.0-beta2. This way, all required libraries are installed automagically. Installing Homebrew Installation of Homebrew is well documented on the Homebrew website Similarly to MacPorts, the default install path is /usr/opt/local* so you may need to do a similar trick as above, passing compiler or linker flags, and/or updating the PATH env variable itself. Luckily, the Homebrew package manager will advise you when this is necessary. At of 2017 three libraries seem to be particularly troublesome since Apple includes old or incomplete versions of these libraries in the base OS (Sierra and High Sierra): gettext, libtool, and icu4c. gettext - there is a clash with the MacOSX version of the gettext tools. Use % brew link gettext --force to force the system to use the homebrew version before running autoconf.sh. You can use % brew unlink gettext to undo this if necessary. Libtool - '''Homebrew renames the binaries as 'glibtool' and 'glibtoolize' to avoid conflict which the Freeciv bootstrapping script struggles to detect. See for more information. '''icu4c - Homebrew does not install the metadata used by configure '''by default. Fix this by asking Homebrew to rebuild icu4c from source, then adding the metadata using pkg-config: % brew reinstall --build-from-source icu4c % pkg-config icu4c Installing Fink Instructions to install Fink can be found here. It's recomended that you use the included FinkCommander. You will want to install the following packages: (installing the '''shlib and dev packages is recomended) GTK +X11 *Install X11 and X11 SDK components. Both are available on your Mac OS X CD. However, X11 itself is also available as a download (Panther compatible download here) from Apple. *Install Xcode 1.2, 1.5 (For Panther), 2.0 (For Tiger) or 3.0 (For Leopard) *GTK+ 2.0 client - If done by a package manager, the supporting packages will be installed automatically. ** gettext ** glib2 ** pango ** atk ** gtk2 GTK +quartz (Does not yet work. Edit: As of OS X 10.8, Mountain Lion, XQuartz appears to work (may work on earlier, not tested). ) *Install Xcode 1.2, 1.5 (For Panther), 2.0 (For Tiger) or 3.0 (For Leopard) *GTK+ 2.0 client - If done by a package manager, the supporting packages will be installed automatically. ** gettext ** glib2 ** pango ** atk ** gtk2 SDL As of 2.2.0, the SDL client is not as plush as the GTK client. For instance, the SDL interface does not recognize a scroll wheel on a mouse. GTK not only does, it also recognizes trackpad gestures. The required packages are: * SDL * libpng * freetype * SDL_image Build and install in above order, then compile the Freeciv tarball with "--enable-client=sdl". SDL Client with MacPorts I've been able to build the SDL client using the libs provided by MacPorts. Changing the "--cflags)" section of /opt/local/bin/sdl-config to -I${prefix}/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE \ -I${prefix}/include/ -Dmain=SDL_main Configure and Setup (1) Get Source * Option A: get source tarball from here and extract it. * Option B: get a fresh source tree from the Freeciv source code repository * Note where you put this. This directory is the prefix directory. We'll refer to it later. At this point, it's a good idea to read the INSTALL file located in the top-level directory of the archive. It contains information on dependencies and other useful information. (2) autogen.sh This step applies only if you're building from a development version of the source (git) (Option B). * Note: This will also run configure. If you know what you're doing, you can pass the 'configure' arguments directly to autogen.sh, and you may then skip step (3) below. (3) configure * Set up your environment: % env CC="gcc -no-cpp-precomp" CFLAGS="-O3" :Note: As of High Sierra, these parameters don't seem to be necessary anymore. : :* To build the GTK 3.22 client, execute this configure 'command from the command line, at the top-level directory of the source archive: % ./configure --enable-client=gtk3.22 \ --with-x-funcproto='FUNCPROTO=15 NARROWPROTO' ''Note: This was tested on High Sierra. On older systems with different X11 configurations the --with-x-funcproto clause may need modifications. Try omitting this clause and allowing configure to figure it out automatically - but on High Sierra the detection hangs without this clause. * To build the GTK+2 client, execute this '''configure command from the command line, at the top-level directory of the source archive: % ./configure \ --enable-client=gtk2 \ --prefix=/Users/your_user_name/your_chosen_directory *On Leopard add: --with-readline=builtin --with-libiconv-prefix=${prefix}/include * As of version 2.1.13 there is a bug which requires building without readline (this bug does not seem to be present in 2.2.0-beta1 onwards): % --without-readline * If ngettext isn't found, you will be prompted to add "--disable-nls". Compile (4) Run Make *Compile the source by executing this command: % make (4b) Troubleshooting Potential Errors During Compiling Compiling Freeciv using the before specified commands may yield the following error: stdinhand.c: In function 'freeciv_completion': stdinhand.c:4509: error: 'rl_attempted_completion_over' undeclared (first use in this function) stdinhand.c:4509: error: (Each undeclared identifier is reported only once stdinhand.c:4509: error: for each function it appears in.) make3: *** stdinhand.o Error 1 make2: *** all-recursive Error 1 make1: *** all-recursive Error 1 make: *** all Error 2 A workaround for this problem was mentioned on the old Freeciv-Dev Mailing list: You can probably work around it by running ./configure --without-readline. However it would be nice to fix it if you'll help us track down the problem. This applies to users of Mac OS X 10.4 (Tiger). If you receive a link error like the following: Undefined symbols: "_iconv_close", referenced from: _convert_string in libfreeciv.a(fciconv.o) _convert_string in libfreeciv.a(fciconv.o) "_iconv_open", referenced from: _convert_string in libfreeciv.a(fciconv.o) "_iconv", referenced from: _convert_string in libfreeciv.a(fciconv.o) _convert_string in libfreeciv.a(fciconv.o) "_locale_charset", referenced from: _init_character_encodings in libfreeciv.a(fciconv.o) ld: symbol(s) not found collect2: ld returned 1 exit status make3: *** freeciv-gtk2 Error 1 make2: *** all-recursive Error 1 make1: *** all-recursive Error 1 make: *** all Error 2 It means you are probably linking against iconv version 1.13; you need to install the latest libiconv. You can find instructions here. Untar to a directory and change to it: % ./configure --prefix=/opt/local % make % sudo make install Which will install it with the MacBuilds directory or replace /opt/local with /sw for Fink. Now, you need to reconfigure and rebuild freeciv; switch to your freeciv source directory and type: % make clean % ./configure --enable-client=gtk2 --prefix=/opt/local --disable-nls --with-libiconv-prefix=/opt/local % make Install (5) Test If you've gotten this far, test your shiny new program. This command will run the client. % ./fcgui (6) Install and Enjoy Assuming everything works properly, execute this command to install it in directory you specified as the prefix:prefix: % make install *Now, you should be able to find some executables in the /''prefix''/bin directory: freeciv-gtk2 freeciv-sdl freeciv-server freeciv-manual You might have success in launching the client by simply double-clicking on the client executable from within the Finder, however this will typically pop up a terminal similar to a DOS window on a PC. In order to create a true clickable icon for the finder, you need to use AppleScript. You can find the Script Editor in the Utilities subfolder of the Applications folder. Open that and and enter: do shell script "/opt/local/bin/freeciv-gtk2" Or /sw instead of /opt/local depending on whether you installed via Fink; or your home directory path to the executable as the case may be. Save this to your applications folder and select "Application" for the file format and check "Run Only". Click save. It is possible with this, the server may not be able to start. This is because even if you set the path in your .profile, the shell script is not run as a login shell and thus the .profile will not be executed so the folder where the server is located may not be in the PATH variable. There is a UNIX trick to force the PATH to include more elements. For instance, if you installed freeciv in /opt/local, you can change your script to read: do shell script "PATH=/opt/local/bin:$PATH /opt/local/bin/freeciv-gtk2" If you have an icon you want to use such as the one to the left, option-click and Copy Image it into the paste buffer and edit the properties through the Get Info option click on the resulting script in the finder. In the Info window, select the default icon and then press Command-V to paste in your icon. * Enjoy! Optional Support Sound Support You need to install the following for SDL sound support: * libsdl SDL_sound tarball * libsdl_mixer SDL_mixer tarball * libogg libogg tarball * This is needed so that sdl-sound can actually play the sounds in the soundset, which are in OGG format. When running Freeciv's configure script, be sure to use the following option: --with-sdl-prefix=/opt/local Furthermore, you need to define your CC environment variable to be the following: gcc= " -no-cpp-precomp -I/opt/local/include -L/opt/local/lib" After you have built the binaries, copy the .soundspec file, and the accompanying folder containing the actual sound files from the sound set archive into your path_to_freeciv/share/freeciv directory. Localization Support You need to have a functioning installation of the gettext package to be able to run Freeciv with a language other than English. When running Freeciv's configure script, be sure to use the following option: --enable-nls Furthermore, you need to define your CC environment variable to be the following (to where MacPorts install packages): gcc = "-no-cpp-precomp -I/opt/local/include -L/opt/local/lib" You may start either the server or client or both in the locale of your choice by giving a full LANG prefix when executing them. E.G. the client in Swedish locale: LANG="sv_SE.UTF-8 freeciv-gtk2" Note that by giving a full locale string as the example above, you avoid potential encoding conversion warnings and glitches. Category:Installing